#pragma once
#include "stdafx.h"
//-------------------------------------------------------------------------------------------------
//ImageProcessFile.h  - Declaration of an Image Processing File (IPF)          
//-------------------------------------------------------------------------------------------------
//FreeBSD License
//Copyright 2012 Will Stott All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//      conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//      of conditions and the following disclaimer in the documentation and/or other materials
//      provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Will Stott ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Will Stott OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Will Stott.
//
//----Authors--------------------------------------------------------------------------------------
//created by: will.stott@ucl.ac.uk Feb 2012
//
//----Comments-------------------------------------------------------------------------------------
//
//-------------------------------------------------------------------------------------------------
#ifdef IMAGEEXPTLIB_EXPORTS
#define IMAGEEXPTLIBAPI __declspec(dllexport)
#else
#define IMAGEEXPTLIBAPI __declspec(dllimport)
#endif

#include "ImageProcSteps.h"

class IMAGEEXPTLIBAPI ImageProcessFile
{
public:
	static const char * const ImageProcessFile::Invalid;

	static const char * const ImageProcessFile::IpfRefPrefix;

	static const char * const ImageProcessFile::xmlHeader;
	static const char * const ImageProcessFile::xmlHeaderAttribName;
	static const char * const ImageProcessFile::xmlHeaderAttribDescription;
	static const char * const ImageProcessFile::xmlHeaderAttribStatus;
	static const char * const ImageProcessFile::xmlHeaderAttribIPFRef;
	static const char * const ImageProcessFile::xmlHeaderAttribIEFRef;
	static const char * const ImageProcessFile::xmlHeaderAttribOwner;
	static const char * const ImageProcessFile::xmlHeaderAttribDate;

	static const char * const ImageProcessFile::xmlImages;			//match with ImageDataset::xmlImages
	static const char * const ImageProcessFile::xmlImage;			//match with ImageDataset::xmlImage
	static const char * const ImageProcessFile::xmlNoImageFilename; //match with ImageDataset::xmlNoImageFilename

	static const char * const ImageProcessFile::StatusExperimental;
	static const char * const ImageProcessFile::StatusProduction;

	static const int		  ImageProcessFile::NameLenMax = 30;
	static const int		  ImageProcessFile::DescriptionLenMax = 150;
	static const int		  ImageProcessFile::StatusLenMax = 50;

	static const char * const DateTimeFrmStr;			//match with ImageExpt::DateTimeFrmStr and ImageDataset::DateTimeFrmStr

	static const int		  DateTimeFrmStrLen = 20;	//match with ImageExpt::DateTimeFrmStr and ImageDataset::DateTimeFrmStr
	static const int		  OwnerLenMax = 25;			//match with ImageExpt::OwnerLenMax and ImageDataset::OwnerLenMax
	static const int		  IEFRefLenMax  = sizeof(IpfRefPrefix) + 1 + OwnerLenMax + 1 + DateTimeFrmStrLen + 1;	//match with ImageExpt::IEFRefMax and ImageDataset::::IDFRefMax



public:
	ImageProcessFile(void);
	~ImageProcessFile(void);

	bool Init (const wchar_t *intermedImagePathfilename, const wchar_t *imageProcLibDir);
	bool SetHeaderDetails(const wchar_t *name, const wchar_t *description, const wchar_t *status, const wchar_t *iefRef );
	bool Save(const wchar_t *pathfilename);
	bool Validate();

	bool IsInit() { return _ReadyToSetSteps; }
	bool IsValid() { return ((_error == false) ? true : false); }
	bool IsValidSteps() { return (((_pSteps != '\0') && (_pSteps->IsValid())) ? true : false); }

	const char *GetName() { return _Name.c_str(); }
	const char *GetDescription() { return _Description.c_str(); }
	const char *GetStatus() { return _Status.c_str(); }
	const char *GetIpfRef() { return _IpfRef.c_str(); }
	const char *GetIefRef() { return _IefRef.c_str(); }
	const char *GetOwner() { return _Owner.c_str(); }
	const char *GetDate() { return _Date.c_str(); }
	const char *GetPathFilename() { return _PathFilename.c_str(); }
	const char *GetIntermedImagePathFilename() { return (((IsInit() == true) && (_pSteps != '\0')) ? _pSteps->GetImageIntermediatePathFilename() : ImageProcSteps::BadImageIntermedPathFilename); }

	bool		SetPathFilename(const wchar_t *pathfilename);
	bool		SetOwner(const wchar_t *owner);

	ImageProcSteps		*GetSteps() { return _pSteps; }
	ImageProcStepLibs	*GetLibs() { return _pImageProcStepLibs; }
private:
	bool				_error;
	bool				_ReadyToSetSteps;
	ImageProcSteps		*_pSteps;
	ImageProcStepLibs	*_pImageProcStepLibs;

#pragma warning(disable:4251)
	std::string			_Name;
	std::string			_Description;
	std::string			_Status;
	std::string			_IpfRef;
	std::string			_IefRef;
	std::string			_Owner;
	std::string			_Date;
	std::string			_PathFilename;
#pragma warning(default:4251)

private:
	bool		InitLibs (const wchar_t *imageProcLibDir);
	bool		SaveToXml(const char *pathfilename);
	bool		SetHeader(TiXmlElement * pHeader);
	void		SetIdentity();
	void		SetDate();

private:
	char		_buff[ImageExptLib::MaxPathFileNameLen+1];
};

//-------------------------------------------------------------------------------------------------
//			E N D   O F   F I L E
//-------------------------------------------------------------------------------------------------